package com.xyck.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xyck.common.annotation.Log;
import com.xyck.common.core.controller.BaseController;
import com.xyck.common.core.domain.AjaxResult;
import com.xyck.common.enums.BusinessType;
import com.xyck.manage.domain.Records;
import com.xyck.manage.service.IRecordsService;
import com.xyck.common.utils.poi.ExcelUtil;
import com.xyck.common.core.page.TableDataInfo;

/**
 * 记录管理Controller
 * 
 * @author 星野漫游
 * @date 2024-07-08
 */
@RestController
@RequestMapping("/manage/records")
public class RecordsController extends BaseController
{
    @Autowired
    private IRecordsService recordsService;

    /**
     * 查询记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(Records records)
    {
        startPage();
        List<Records> list = recordsService.selectRecordsList(records);
        return getDataTable(list);
    }

    /**
     * 导出记录管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:records:export')")
    @Log(title = "记录管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Records records)
    {
        List<Records> list = recordsService.selectRecordsList(records);
        ExcelUtil<Records> util = new ExcelUtil<Records>(Records.class);
        util.exportExcel(response, list, "记录管理数据");
    }

    /**
     * 获取记录管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(recordsService.selectRecordsById(id));
    }

    /**
     * 新增记录管理
     */
    @PreAuthorize("@ss.hasPermi('manage:records:add')")
    @Log(title = "记录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Records records)
    {
        return toAjax(recordsService.insertRecords(records));
    }

    /**
     * 修改记录管理
     */
    @PreAuthorize("@ss.hasPermi('manage:records:edit')")
    @Log(title = "记录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Records records)
    {
        return toAjax(recordsService.updateRecords(records));
    }

    /**
     * 删除记录管理
     */
    @PreAuthorize("@ss.hasPermi('manage:records:remove')")
    @Log(title = "记录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(recordsService.deleteRecordsByIds(ids));
    }
}
